﻿using System;
using System.Collections.Generic;
using Wisdom.Core.Specifications;
using System.Linq.Expressions;

namespace Wisdom.Core.Repositories
{
    /// <summary>
    /// 仓库基类(抽像类).
    /// </summary>
    /// <typeparam name="TAggregateRoot">聚合根在仓库中可被执行.</typeparam>
    public abstract class Repository<TAggregateRoot> : IRepository<TAggregateRoot>
        where TAggregateRoot : class, IAggregateRoot
    {
        #region Private Fields
        private readonly IRepositoryContext _context;
        #endregion

        #region Ctor
        /// <summary>
        /// Initializes a new instance of <c>Repository&lt;TAggregateRoot&gt;</c> class.
        /// </summary>
        /// <param name="context">The repository _context being used by the repository.</param>
        protected Repository(IRepositoryContext context)
        {
            this._context = context;
        }
        #endregion

        #region Protected Methods

        #region Abstract Methods
        /// <summary>
        /// Adds an aggregate root to the repository.
        /// </summary>
        /// <param name="aggregateRoot">The aggregate root to be added to the repository.</param>
        protected abstract void DoAdd(TAggregateRoot aggregateRoot);
        /// <summary>
        /// Removes the aggregate root from current repository.
        /// </summary>
        /// <param name="aggregateRoot">The aggregate root to be removed.</param>
        protected abstract void DoRemove(TAggregateRoot aggregateRoot);
        /// <summary>
        /// Updates the aggregate root in the current repository.
        /// </summary>
        /// <param name="aggregateRoot">The aggregate root to be updated.</param>
        protected abstract void DoUpdate(TAggregateRoot aggregateRoot);
        /// <summary>
        /// Checkes whether the aggregate root, which matches the given specification, exists in the repository.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate root should match.</param>
        /// <returns>True if the aggregate root exists, otherwise false.</returns>
        protected abstract bool DoExists(ISpecification<TAggregateRoot> specification);
        /// <summary>
        /// Gets the aggregate root instance from repository by a given key.
        /// </summary>
        /// <param name="key">The key of the aggregate root.</param>
        /// <returns>The instance of the aggregate root.</returns>
        protected abstract TAggregateRoot DoFindByKey(Guid key);
        /// <summary>
        /// Finds a single aggregate root that matches the given specification.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate root should match.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>The instance of the aggregate root.</returns>
        protected abstract TAggregateRoot DoFind(ISpecification<TAggregateRoot> specification, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties);
        /// <summary>
        /// Gets all the aggregate roots that match the given specification, and sorts the aggregate roots
        /// by using the provided sort predicate and the specified sort order.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots that match the given specification and were sorted by using the given sort predicate and the sort order.</returns>
        protected abstract IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties);
        /// <summary>
        /// Gets all the aggregate roots that match the given specification with paging enabled, and sorts the aggregate roots
        /// by using the provided sort predicate and the specified sort order.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots that match the given specification and were sorted by using the given sort predicate and the sort order.</returns>
        protected abstract IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties);
        #endregion

        #region Virtual Methods
        /// <summary>
        /// Finds a single aggregate root that matches the given specification.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate root should match.</param>
        /// <returns>The instance of the aggregate root.</returns>
        protected virtual TAggregateRoot DoFind(ISpecification<TAggregateRoot> specification)
        {
            return this.DoFind(specification, null);
        }

        /// <summary>
        /// Gets all the aggregate roots from repository.
        /// </summary>
        /// <returns>All the aggregate roots got from the repository.</returns>
        /// <summary>
        /// Finds all the aggregate roots from repository.
        /// </summary>
        /// <returns>All the aggregate roots got from the repository.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll()
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>());
        }
        /// <summary>
        /// Finds all the aggregate roots from repository with paging enabled.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <returns>All the aggregate roots got from the repository.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(int pageNumber, int pageSize)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), pageNumber, pageSize);
        }

        /// <summary>
        /// Finds all the aggregate roots from repository, sorting by using the provided sort predicate
        /// and the specified sort order.
        /// </summary>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <returns>All the aggregate roots got from the repository, with the aggregate roots being sorted by
        /// using the provided sort predicate and the sort order.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), orderByParameters);
        }

        /// <summary>
        /// Finds all the aggregate roots from repository with paging enabled, sorting by using the provided sort predicate
        /// and the specified sort order.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <returns>All the aggregate roots got from the repository, with the aggregate roots being sorted by
        /// using the provided sort predicate and the sort order.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), pageNumber, pageSize, orderByParameters);
        }
        /// <summary>
        /// Finds all the aggregate roots that match the given specification.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <returns>All the aggregate roots that match the given specification.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification)
        {
            return DoFindAll(specification, orderByParameters: null);
        }
        /// <summary>
        /// Finds all the aggregate roots that match the given specification with paging enabled.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <returns>All the aggregate roots that match the given specification.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize)
        {
            return DoFindAll(specification, pageNumber, pageSize, orderByParameters: null);
        }
        /// <summary>
        /// Gets all the aggregate roots from repository.
        /// </summary>
        /// <returns>All the aggregate roots got from the repository.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), eagerLoadingProperties);
        }
        /// <summary>
        /// Gets all the aggregate roots from repository with paging enabled.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots for the specified page.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// Gets all the aggregate roots from repository, sorting by using the provided sort predicate
        /// and the specified sort order.
        /// </summary>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots got from the repository, with the aggregate roots being sorted by
        /// using the provided sort predicate and the sort order.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// Gets all the aggregate roots from repository with paging enabled, sorting by using the provided sort predicate
        /// and the specified sort order.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots got from the repository for the specified page, with the aggregate roots being sorted by
        /// using the provided sort predicate and the sort order.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return DoFindAll(new AnySpecification<TAggregateRoot>(), pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }
        /// <summary>
        /// Gets all the aggregate roots that match the given specification.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots that match the given specification.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return DoFindAll(specification, null, eagerLoadingProperties);
        }
        /// <summary>
        /// Gets all the aggregate roots that match the given specification with paging enabled.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <param name="eagerLoadingProperties">The properties for the aggregated objects that need to be loaded.</param>
        /// <returns>All the aggregate roots that match the given specification.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return DoFindAll(specification, pageNumber, pageSize, null, eagerLoadingProperties);
        }
        /// <summary>
        /// Finds all the aggregate roots that match the given specification with paging enabled, and sorts the aggregate roots
        /// by using the provided sort predicate and the specified sort order.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="pageNumber">The number of objects per page.</param>
        /// <param name="pageSize">The number of objects per page.</param>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <returns>All the aggregate roots that match the given specification and were sorted by using the given sort predicate and the sort order.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return DoFindAll(specification, pageNumber, pageSize, orderByParameters, null);
        }

        /// <summary>
        /// Finds all the aggregate roots that match the given specification, and sorts the aggregate roots
        /// by using the provided sort predicate and the specified sort order.
        /// </summary>
        /// <param name="specification">The specification with which the aggregate roots should match.</param>
        /// <param name="orderByParameters">The <see>
        ///                                       <cref>OrderyByParameter</cref>
        ///                                     </see> array which is used for sorting.</param>
        /// <returns>All the aggregate roots that match the given specification and were sorted by using the given sort predicate and the sort order.</returns>
        protected virtual IEnumerable<TAggregateRoot> DoFindAll(ISpecification<TAggregateRoot> specification, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return DoFindAll(specification, orderByParameters, null);
        }
        #endregion

        #endregion

        #region Implementation of IRepository<TAggregateRoot>

        /// <summary>
        /// 获得仓库上下文.
        /// </summary>
        public IRepositoryContext Context
        {
            get { return this._context; }
        }

        /// <summary>
        /// 添加一个聚合根到仓库.
        /// </summary>
        /// <param name="aggregateRoot">聚合根.</param>
        public void Add(TAggregateRoot aggregateRoot)
        {
            this.DoAdd(aggregateRoot);
        }

        /// <summary>
        /// 添加枚举聚合根到仓库.
        /// </summary>
        /// <param name="aggregateRoots">聚合根.</param>
        public void Add(IEnumerable<TAggregateRoot> aggregateRoots)
        {
            aggregateRoots.ForEach(this.DoAdd);
        }

        /// <summary>
        /// 从仓库移出指定的聚合根.
        /// </summary>
        /// <param name="aggregateRoot">要移出的聚合根.</param>
        public void Remove(TAggregateRoot aggregateRoot)
        {
            this.DoRemove(aggregateRoot);
        }

        /// <summary>
        /// 从仓库移出指定的枚举聚合根.
        /// </summary>
        /// <param name="aggregateRoots">要移出的聚合根.</param>
        public void Remove(IEnumerable<TAggregateRoot> aggregateRoots)
        {
            aggregateRoots.ForEach(this.DoRemove);
        }

        /// <summary>
        /// 从仓库移出所有符合给定的聚合根元素.
        /// </summary>
        /// <param name="specification">聚合根元素</param>
        public void Remove(ISpecification<TAggregateRoot> specification)
        {
            var aggregateRoots = this.GetAll(specification);
            aggregateRoots.ForEach(this.DoRemove);
        }

        /// <summary>
        /// 从仓库移出所有符合委托表达式的聚合根.
        /// </summary>
        /// <param name="specExpression">符合委托表达式的聚合根</param>
        public void Remove(Expression<Func<TAggregateRoot, bool>> specExpression)
        {
            var aggregateRoots = this.GetAll(specExpression);
            aggregateRoots.ForEach(this.DoRemove);
        }

        /// <summary>
        /// 更新指定的聚合根.
        /// </summary>
        /// <param name="aggregateRoot">指定的聚合根.</param>
        public void Update(TAggregateRoot aggregateRoot)
        {
            this.DoUpdate(aggregateRoot);
        }

        /// <summary>
        /// 更新指定的枚举聚合根.
        /// </summary>
        /// <param name="aggregateRoots">可枚举聚合根.</param>
        public void Update(IEnumerable<TAggregateRoot> aggregateRoots)
        {
            aggregateRoots.ForEach(this.DoUpdate);
        }

        /// <summary>
        /// 在仓库添加或更新指定的聚合根.
        /// </summary>
        /// <param name="aggregateRoot">添加或更新指定的聚合根.</param>
        public void AddOrUpdate(TAggregateRoot aggregateRoot)
        {
            if (aggregateRoot.Id == Guid.Empty)
                this.DoAdd(aggregateRoot);
            else
                this.DoUpdate(aggregateRoot);
        }

        /// <summary>
        /// 在仓库添加或更新指定的枚举聚合根.
        /// </summary>
        /// <param name="aggregateRoots">添加或更新指定的枚举聚合根.</param>
        public void AddOrUpdate(IEnumerable<TAggregateRoot> aggregateRoots)
        {
            aggregateRoots.ForEach(this.AddOrUpdate);
        }

        /// <summary>
        /// 判断指定的枚举聚合根是否存在于仓库里.
        /// </summary>
        /// <param name="specification">匹配的枚举聚合根.</param>
        /// <returns>True 如果存在聚合根, 否则 false.</returns>
        public bool Exists(ISpecification<TAggregateRoot> specification)
        {
            return this.DoExists(specification);
        }

        /// <summary>
        /// 判断指定的枚举聚合根委托是否存在于仓库里.
        /// </summary>
        /// <param name="specExpression">枚举聚合根委托.</param>
        /// <returns>True 如果存在聚合根, 否则 false.</returns>
        public bool Exists(Expression<Func<TAggregateRoot, bool>> specExpression)
        {
            return this.DoExists(Specification<TAggregateRoot>.Eval(specExpression));
        }

        /// <summary>
        /// 通过指定的键获得聚合根.
        /// </summary>
        /// <param name="key">聚合根的键.</param>
        /// <returns>符合条件的聚合根.</returns>
        public TAggregateRoot GetByKey(Guid key)
        {
            return this.DoFindByKey(key);
        }

        /// <summary>
        /// 通过指定的聚合根规则获得一个符合条件的聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <returns>符合条件的聚合根.</returns>
        public TAggregateRoot Get(ISpecification<TAggregateRoot> specification)
        {
            return this.DoFind(specification);
        }

        /// <summary>
        /// 通过指定的枚举聚合根规则获得一个符合条件的聚合根.
        /// </summary>
        /// <param name="specExpression">枚举聚合根规则.</param>
        /// <returns>符合条件的聚合根</returns>
        public TAggregateRoot Get(Expression<Func<TAggregateRoot, bool>> specExpression)
        {
            return this.DoFind(Specification<TAggregateRoot>.Eval(specExpression));
        }

        /// <summary>
        /// 通过指定的聚合根规则获得一个符合条件的聚合根
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="eagerLoadingProperties">聚合根表达式参数.</param>
        /// <returns>符合条件的聚合根.</returns>
        public TAggregateRoot Get(ISpecification<TAggregateRoot> specification, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFind(specification, eagerLoadingProperties);
        }

        /// <summary>
        /// 通过指定的枚举聚合根表达式获得一个符合条件的聚合根.
        /// </summary>
        /// <param name="specExpression">枚举聚合根表达式.</param>
        /// <param name="eagerLoadingProperties">静态式聚合根参数.</param>
        /// <returns>符合条件的聚合根.</returns>
        public TAggregateRoot Get(Expression<Func<TAggregateRoot, bool>> specExpression, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFind(Specification<TAggregateRoot>.Eval(specExpression), eagerLoadingProperties);
        }

        /// <summary>
        /// 获得仓库所有的聚合根.
        /// </summary>
        /// <returns>所有的聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll()
        {
            return this.DoFindAll();
        }

        /// <summary>
        /// 获得分页中指定页的所有聚合根
        /// </summary>
        /// <param name="pageNumber">页的索引号.</param>
        /// <param name="pageSize">每页显示大小.</param>
        /// <returns>指定页号，指定大小的所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(int pageNumber, int pageSize)
        {
            return this.DoFindAll(pageNumber, pageSize);
        }

        /// <summary>
        /// 获得所有通过排序参数对枚举聚合根排序
        /// </summary>
        /// <param name="orderByParameters">参数 <see>
        ///                                       <cref>排序参数</cref>
        ///                                     </see> 排序聚合根参数.</param>
        /// <returns>所有通过排序参数对枚举聚合根排序</returns>
        public IEnumerable<TAggregateRoot> GetAll(OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(orderByParameters);
        }

        /// <summary>
        /// 通过获得分页获得页大小的聚合根，并排序
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="orderByParameters">排序聚合根参数.</param>
        /// <returns>分页获得页大小的聚合根，并排序</returns>
        public IEnumerable<TAggregateRoot> GetAll(int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(pageNumber, pageSize, orderByParameters);
        }

        /// <summary>
        /// 获得符合枚举聚合根规则所有聚合根.
        /// </summary>
        /// <param name="specification">枚举聚合根规则.</param>
        /// <returns>符合枚举聚合根规则所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification)
        {
            return this.DoFindAll(specification);
        }

        /// <summary>
        /// 获得所有符合枚举聚合根表达式的聚合根元素.
        /// </summary>
        /// <param name="specExpression">枚举聚合根表达式.</param>
        /// <returns>所有符合枚举聚合根表达式的聚合根元素.</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression));
        }

        /// <summary>
        /// 获得符合聚合根规则，并在指定分页大小及页索引内的所有聚合根
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引.</param>
        /// <param name="pageSize">页大小.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize)
        {
            return this.DoFindAll(specification, pageNumber, pageSize);
        }

        /// <summary>
        ///  获得符合聚合根表达式，并在指定分页大小及页索引内的所有聚合根
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize);
        }

        /// <summary>
        /// 获得符合聚合根规则并按排序参数排序后的所有聚合根
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="orderByParameters">聚合根排序参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(specification, orderByParameters);
        }

        /// <summary>
        /// 获得符合聚合根表达式并按排序参数排序后的所有聚合根
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="orderByParameters">聚合根排序参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), orderByParameters);
        }

        /// <summary>
        /// 获得符合聚合根规则、并在指定的分页页码及页大小中并按排序参数排序后的所有聚合根
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="orderByParameters">聚合根排序参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(specification, pageNumber, pageSize, orderByParameters);
        }

        /// <summary>
        /// 获得符合聚合根表达式、并在指定的分页页码及页大小中并按排序参数排序后的所有聚合根
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="orderByParameters">聚合根排序参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize, orderByParameters);
        }

        /// <summary>
        /// 获得所有的聚合根.
        /// </summary>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有分页中指定页大小和索引页的聚合根.
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="eagerLoadingProperties">聚合根表达式参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得根据聚合根表达式进行排序的所有聚合根.
        /// </summary>
        /// <param name="orderByParameters">聚合根排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根表达式参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得通过分页，排序的聚合根
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="orderByParameters">排序数据.</param>
        /// <param name="eagerLoadingProperties">聚合根表达式参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根规则的聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根表达式的聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根规则并在指定分页页面的所有聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根表达式并在指定分页页面的所有聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根.</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根规则聚合根
        /// </summary>
        /// <param name="specification">聚合根规则</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根表达式聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根规则并在分页数据页范围内的所有聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> GetAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 获得所有符合聚合根表达式并在分页数据页范围内的所有聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> GetAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找根据聚合根键查找聚合根.
        /// </summary>
        /// <param name="key">聚合根键.</param>
        /// <returns>聚合根.</returns>
        public TAggregateRoot FindByKey(Guid key)
        {
            return this.DoFindByKey(key);
        }

        /// <summary>
        /// 查找符合聚合根规则的所有聚合根.
        /// </summary>
        /// <param name="specification">匹配规则.</param>
        /// <returns>合聚合根规则的所有聚合根.</returns>
        public TAggregateRoot Find(ISpecification<TAggregateRoot> specification)
        {
            return this.DoFind(specification);
        }

        /// <summary>
        /// 查找符合聚合根表达式的所有聚合根.
        /// </summary>
        /// <param name="specExpression">匹配表达式.</param>
        /// <returns>合聚合根表达式的所有聚合根</returns>
        public TAggregateRoot Find(Expression<Func<TAggregateRoot, bool>> specExpression)
        {
            return this.DoFind(Specification<TAggregateRoot>.Eval(specExpression));
        }

        /// <summary>
        /// 查找符合聚合根规则的所有聚合根
        /// </summary>
        /// <param name="specification">匹配规则.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合聚合根规则的所有聚合根.</returns>
        public TAggregateRoot Find(ISpecification<TAggregateRoot> specification, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFind(specification, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根表达式的所有聚合根
        /// </summary>
        /// <param name="specExpression">匹配表达式.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合聚合根表达式的所有聚合根.</returns>
        public TAggregateRoot Find(Expression<Func<TAggregateRoot, bool>> specExpression, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFind(Specification<TAggregateRoot>.Eval(specExpression), eagerLoadingProperties);
        }

        /// <summary>
        /// 查找所有聚合根.
        /// </summary>
        /// <returns>所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll()
        {
            return this.DoFindAll();
        }

        /// <summary>
        /// 查找符合分页页面所有聚合根.
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <returns>符合聚合根分页的所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(int pageNumber, int pageSize)
        {
            return this.DoFindAll(pageNumber, pageSize);
        }

        /// <summary>
        /// 查找所有聚合根并根据排序参数排序.
        /// </summary>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(orderByParameters);
        }

        /// <summary>
        /// 查找符合分页页面所有聚合根并按排序参数排序.
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合聚合根分页的所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(pageNumber, pageSize, orderByParameters);
        }

        /// <summary>
        /// 查找符合聚合根规则的所有聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <returns>符合聚合根规则的所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification)
        {
            return this.DoFindAll(specification);
        }

        /// <summary>
        /// 查找符合聚合根表达式的所有聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <returns>符合聚合根表达式的所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression));
        }

        /// <summary>
        /// 查找符合聚合根规则并符合分页页面所有聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <returns>符合聚合根规则并符合分页页面所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize)
        {
            return this.DoFindAll(specification, pageNumber, pageSize);
        }

        /// <summary>
        /// 查找符合聚合根表达式并符合分页页面所有聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <returns>符合聚合根表达式并符合分页页面所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize);
        }

        /// <summary>
        /// 查找符合聚合根规则所有聚合根并排序.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(specification, orderByParameters);
        }

        /// <summary>
        /// 查找符合聚合根表达式所有聚合根并排序.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), orderByParameters);
        }

        /// <summary>
        /// 查找符合聚合根规则并符合分页页面所有聚合根,并排序.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(specification, pageNumber, pageSize, orderByParameters);
        }

        /// <summary>
        /// 查找符合聚合根表达式并符合分页页面所有聚合根,并排序.
        /// </summary>
        /// <param name="specExpression">根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize, orderByParameters);
        }

        /// <summary>
        /// 查找所有聚合根.
        /// </summary>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合分页页面所有聚合根
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合分页页面所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找所有聚合根并按排序参数排序
        /// </summary>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合分页页面所有聚合根,并排序.
        /// </summary>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合分页页面所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根规则所有聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合聚合根规则所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根表达式所有聚合根
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合聚合根表达式所有聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根规则并符合分页页面所有聚合根.
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合聚合根规则并符合分页页面所有聚合根.</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根表达式并符合分页页面所有聚合根.
        /// </summary>
        /// <param name="specExpression">聚合根表达式</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合聚合根表达式并符合分页页面所有聚合根..</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根规则所有聚合根,并排序
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根表达式所有聚合根,并排序
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根规则并符合分页页面所有聚合根.并排序
        /// </summary>
        /// <param name="specification">聚合根规则.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(specification, pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }

        /// <summary>
        /// 查找符合聚合根表达式并符合分页页面所有聚合根.并排序.
        /// </summary>
        /// <param name="specExpression">聚合根表达式.</param>
        /// <param name="pageNumber">页索引号.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <param name="orderByParameters">排序参数.</param>
        /// <param name="eagerLoadingProperties">聚合根参数.</param>
        /// <returns>符合条件聚合根</returns>
        public IEnumerable<TAggregateRoot> FindAll(Expression<Func<TAggregateRoot, bool>> specExpression, int pageNumber, int pageSize, OrderByParameter<TAggregateRoot>[] orderByParameters, params Expression<Func<TAggregateRoot, dynamic>>[] eagerLoadingProperties)
        {
            return this.DoFindAll(Specification<TAggregateRoot>.Eval(specExpression), pageNumber, pageSize, orderByParameters, eagerLoadingProperties);
        }

        #endregion
    }
}
